package cn.gx.learn.security_boot_jwt_websocket.springsecurity.service;


import cn.gx.learn.security_boot_jwt_websocket.base.dal.database.User;
import cn.gx.learn.security_boot_jwt_websocket.base.dal.mysql.UserMapper;
import cn.gx.learn.security_boot_jwt_websocket.springsecurity.dal.UserDetail;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailService implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user=userMapper.selectByName(username);
        if(user==null){
            throw new UsernameNotFoundException(username);
        }
        return new UserDetail(user);
    }

}
